package net.onceface.application.commons;

import java.io.Serializable;


public class InvokeResult implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3766023916003156733L;

	private Object data;

	private String errorMessage;

	private boolean hasErrors;
	
	/**
	 * 成功处理
	 * **/
	public static InvokeResult success(Object data) {
		InvokeResult result = new InvokeResult();
		result.data = data;
		result.hasErrors = false;
		return result;
	}
	
	public static InvokeResult success() {
		InvokeResult result = new InvokeResult();
		result.hasErrors = false;
		return result;
	}
	
	public static InvokeResult failure(String message) {
		InvokeResult result = new InvokeResult();
		result.hasErrors = true;
		result.errorMessage = message;
		return result;
	}
	
	public Object getData() {
		return data;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public boolean isHasErrors() {
		return hasErrors;
	}

	public boolean isSuccess() {
		return !hasErrors;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	public void setHasErrors(boolean hasErrors) {
		this.hasErrors = hasErrors;
	}
	
}
